var ProduceOrderTemplConfigModel = function (config) {
  BaseModel.call(this);

  var self = this;
  var fn = {
    initData: function (config) {
      self.pageTitle = config.pageTitle;
      self.pageSize = config.pageSize;
      self.showConfig = config.showConfig;

      var orderInfo = new OrderInfoConfigModel(config.orderInfo);
      self.orderInfo = orderInfo;

      var materialColor = new MaterialColorConfigModel(config.materialColor);
      self.materialColor = materialColor;

      var material = new MaterialConfigModel(config.material);
      self.material = material;

      var dragConfig = new DragConfigModel(config.dragConfig);
      self.dragConfig = dragConfig;
    }
  };

  this.getPageSize = function () {
    var pageSize = this.pageSize;
    var width, height;
    var pageText = pageSize.pageText;
    if (pageText === 'A3') {
      if (pageSize.pageDirection === 'vertical') {
        width = 297;
        height = 420;
      } else {
        width = 420;
        height = 297;
      }
    } else if (pageText === 'A4') {
      if (pageSize.pageDirection === 'vertical') {
        width = 210;
        height = 297;
      } else {
        width = 297;
        height = 210;
      }
    }

    width = SysUtil.formatUnit2px(width - 21, 'mm');
    height = SysUtil.formatUnit2px(height - 21, 'mm');
    return {
      width: width + 'px',
      height: height + 'px'
    }
  };

  this.checkValid = function () {
    if (this.pageSize === null) {
      return 'pageSize';
    }
    if (this.pageTitle === '') {
      return 'pageTitle';
    }
    return '';
  };

  this.getObject = function (productOrderData) {
    var postData = {
      pageTitle: this.pageTitle,
      pageSize: this.pageSize,
      showConfig: this.showConfig
    };

    var orderInfo = this.orderInfo;
    postData.orderInfo = orderInfo.getObject();

    var materialColor = this.materialColor;
    postData.materialColor = materialColor.getObject(productOrderData);

    var material = this.material;
    postData.material = material.getObject();

    var dragConfig = this.dragConfig;
    postData.dragConfig = dragConfig.getObject();

    return postData;
  };

  fn.initData(config);
};

ProduceOrderTemplConfigModel.defaultConfig = {
  pageTitle: '生产订单',
  pageSize: {
    pageDirection: "vertical",
    pageText: "A3"
  },
  showConfig: {
    materialColorBom: true,
    materialBom: false,
    projectImg: true,
    otherTable: true
  },
  orderInfo: {
    rowNum: 3,
    colNum: 3,
    widthList: [100, 100, 100, 100, 100, 100, 100],
    fieldList: ["orderNo", "custmer", "proDept", "factoryNo", "custmerOrderNo", "deliveryTime", "orderTotal", "custmerVersionNo", "createUser"]
  },
  materialColor: {
    minHeight: 300,
    fieldObj: {
      customerColor: {
        isShow: true,
        width: 100
      },
      customerColorDescription: {
        isShow: true,
        width: 100
      },
      material: {
        isShow: true
      },
      glasses: {
        isShow: true
      },
      deliveryDate: {
        isShow: true
      },
      orderTotal: {
        isShow: true,
        width: 100
      },
      feedTotal: {
        isShow: true,
        width: 100
      },
      yltsTotal: {
        isShow: false,
        width: 100
      },
      remark: {
        isShow: true,
        width: 100
      }
    },
    materialType: [{
      materialType: "板材圈",
      columns: [{
        isShow: true,
        id: "materialColor",
        width: 100
      }, {
        isShow: true,
        id: "materialColorDescription",
        width: 100
      }]
    }, {
      materialType: "板材肶",
      columns: [{
        isShow: true,
        id: "materialColor",
        width: 100
      }, {
        isShow: true,
        id: "materialColorDescription",
        width: 100
      }]
    }],
    glasses: {},
    deliveryDate: [],
    remarkList: []
  },
  material: {
    minHeight: 200,
    isGroup: false,
    count: 1,
    classifyConfig: [{
      classifyName: "noClassify",
      columns: [{
        isShow: true,
        id: "materialType",
        width: 100
      }, {
        isShow: true,
        id: "materialName",
        width: 100
      }, {
        isShow: true,
        id: "materialModel",
        width: 100
      }, {
        isShow: true,
        id: "orderTotal",
        width: 100
      }, {
        isShow: true,
        id: "feedTotal",
        width: 100
      },{
        isShow: true,
        id: "yltsTotal",
        width: 100
      }]
    }]
  },
  dragConfig: {
    height: 400,
    projectImg: {
      x: 0,
      y: 0,
      width: 200,
      height: 200
    },
    otherTable: []
  }
};
